#include <bits/stdc++.h>

using namespace std;

using ll = long long;

// 并查集

int pre[5000];

void init(int n)
{
    for (int i = 1; i <= n; i++)
        pre[i] = i;
}

int find(int u)
{
    return pre[u] == u ? u : pre[u] = find(pre[u]);
}

void unite(int u, int v)
{
    int ur = find(u);
    int vr = find(v);
    pre[ur] = vr;
}

bool connected(int u, int v)
{
    return find(u) == find(v);
}